#include "comm.hpp"

int main()
{
    bool r = createFifo(NAME_PIPE);
    assert(r);
    (void)r;

    int rfd = open(NAME_PIPE, O_RDONLY);
    if(rfd < 0)
    {
        cout << "errno: " << errno << "err string: " << strerror(errno) << endl;
        exit(1);
    }
    //read
    char buffer[1024];
    while(1)
    {
        ssize_t s = read(rfd, buffer, sizeof(buffer) - 1);
        if(s > 0)
        {
            buffer[s] = 0;
            cout << "进程A->进程B# " << buffer << endl;
        }
        else if(s == 0)
        {
            cout << "进程A quit, me too!" << endl;
            break;
        }
        else
        {
            cout << "errno: " << errno << "err string: " << strerror(errno) << endl;
            break;
        }
    }
    close(rfd);
    removeFifo(NAME_PIPE);
    return 0;
}